package com.rtos.model.process;

import com.rtos.model.memory.MATNode;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Random;

/**
 * @Author: biubiu0002
 * @Date: 2021-08-30 22:21
 * 进程
 * 工厂
 **/
@Data
@AllArgsConstructor
public class Process {
    private PCB pcb;
    private int address;
    private int size;

    private IntegerProperty pid;
    private IntegerProperty restRunTime;
    private IntegerProperty totalRunTime;
    private IntegerProperty lastRunTime;
    private StringProperty deviceType;
    private IntegerProperty blockingTime;

    private MATNode matNode;
    private byte[] exec;

    public Process() {
        this.pcb = new PCB(new Random().nextInt(512));
        this.size=new Random().nextInt(100);
        this.pid=pcb.pidProperty();
        this.restRunTime=pcb.restRunTimeProperty();
        this.totalRunTime=pcb.totalRunTimeProperty();
        this.lastRunTime=pcb.lastRunTimeProperty();
        this.deviceType=pcb.deviceTypeProperty();
        this.blockingTime=pcb.blockingTimeProperty();
        this.exec=pcb.getExec();
    }

    public Process(PCB pcb) {
        this.pcb=pcb;
//        this.size=new Random().nextInt(100);
        this.size=pcb.getSize();
        this.pid=pcb.pidProperty();
        this.restRunTime=pcb.restRunTimeProperty();
        this.totalRunTime=pcb.totalRunTimeProperty();
        this.lastRunTime=pcb.lastRunTimeProperty();
        this.deviceType=pcb.deviceTypeProperty();
        this.blockingTime=pcb.blockingTimeProperty();
        this.exec=pcb.getExec();

    }

    public Process(PCB pcb,int size) {
        this.pcb=pcb;
        this.size=size;
        this.pid=pcb.pidProperty();
        this.restRunTime=pcb.restRunTimeProperty();
        this.totalRunTime=pcb.totalRunTimeProperty();
        this.lastRunTime=pcb.lastRunTimeProperty();
        this.deviceType=pcb.deviceTypeProperty();
        this.blockingTime=pcb.blockingTimeProperty();
        this.exec=pcb.getExec();

    }

    public void setAddress(int address){
        this.address=address;
    }

    public int getAddress() {
        return address;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public IntegerProperty pidProperty() {
        return this.pid;
    }

//    public IntegerProperty priorityProperty() {
//        return this.priority;
//    }

    public IntegerProperty totalRunTimeProperty() {
        return this.totalRunTime;
    }

    public IntegerProperty restRunTimeProperty() {
        return this.restRunTime;
    }

    public IntegerProperty lastRunTimeProperty() {
        return this.lastRunTime;
    }

    public StringProperty deviceTypeProperty(){return this.deviceType;}

    public IntegerProperty blockingTimeProperty(){return this.blockingTime;}
}
